/**
 * Created by python on 19-5-12.
 */
var vm = new Vue({
    el:'#app',
    delimiters:['[[',']]'],
    data:{
        host:host,
        username:'',
        error_username:false,
        error_username_message:'',
        password:'',
        error_password:false,
        error_password_message:''
    },
    methods:{
        check_username: function () {
            var re = /^[a-zA-Z0-9]{5,20}$/;
            if (re.test(this.username)){
                this.error_username = false;
            }else{
                this.error_username = true;
                this.error_username_message = "请输入5-20个字符的用户名";
            }
        },
        check_password: function () {
            var re = /^[a-zA-Z0-9]{8,20}$/;
            if (re.test(this.password)){
                this.error_password = false;
            }else{
                this.error_password = true;
                this.error_password_message = "请输入8-12位的密码";
            }
        },
        on_submit: function () {
            this.check_username();
            this.check_password();
            if (error_username == true || error_password == true) {
                // 出现错误时禁用表单
                window.event.returnValue = false
            }
        },
        // qq登录
        qq_login: function(){
            var next = get_query_string('next') || '/';
            var url = this.host + '/qq/login/?next=' + next;
            axios.get(url, {
                    responseType: 'json'
                })
                .then(response => {
                    location.href = response.data.login_url;
                })
                .catch(error => {
                    console.log(error.response);
                })
        }
    }
});